№1
#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;

typedef struct student {
    char *name;
    int scores[4];
    struct student *next;
} student;

student *create_student(const char *i_name, int score1, int score2, int score3, int score4) {
    student *temp = (student *)malloc(sizeof(student));

    if (temp != NULL) {
        temp->name = strdup(i_name);
        temp->scores[0] = score1;
        temp->scores[1] = score2;
        temp->scores[2] = score3;
        temp->scores[3] = score4;
        temp->next = NULL;
    }

    return temp;
}

student *insert(student *head, const char *i_name, int score1, int score2, int score3, int score4) {
    student *new_student = create_student(i_name, score1, score2, score3, score4);

    if (head == NULL) {
        head = new_student;
    } else {
        student *cursor = head;
        while (cursor->next != NULL) {
            cursor = cursor->next;
        }

        cursor->next = new_student;
    }

    return head;
}

void print_students(student *list) {
    while (list) {
        cout << list->name << " " << list->scores[0] << " " << list->scores[1] << " " << list->scores[2] << " " << list->scores[3] << endl;
        list = list->next;
    }
}

void sort_students(student *head) {
    student *current = head;
    student *index = NULL;
    char temp_name[50];
    int temp_scores[4];

    if (head == NULL) {
        return;
    } else {
        while (current != NULL) {
            index = current->next;

            while (index != NULL) {
                if (strcmp(current->name, index->name) > 0) {
                    strcpy(temp_name, current->name);
                    strcpy(current->name, index->name);
                    strcpy(index->name, temp_name);

                    memcpy(temp_scores, current->scores, sizeof(int) * 4);
                    memcpy(current->scores, index->scores, sizeof(int) * 4);
                    memcpy(index->scores, temp_scores, sizeof(int) * 4);
                }
                index = index->next;
            }
            current = current->next;
        }
    }
}

int main() {
    student *students_list = NULL;

    students_list = insert(students_list, "Маша", 5, 4, 5, 5);
    students_list = insert(students_list, "Саша", 4, 4, 5, 3);
    students_list = insert(students_list, "Арина", 3, 2, 5, 2);
    students_list = insert(students_list, "Милана", 2, 2, 4, 3);
    students_list = insert(students_list, "Милена", 5, 2, 2, 3);

    cout << "Исходник:" << endl;
    print_students(students_list);

    sort_students(students_list);

    cout << endl << "Сортированный:" << endl;
    print_students(students_list);

    return 0;
}









№2
#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;


struct Student {
    char *surname;
    int grades[4];
    Student *prev;
    Student *next;
};


Student *createStudent(const char *surname, int grade1, int grade2, int grade3, int grade4) {
    Student *newStudent = new Student;
    newStudent->surname = strdup(surname);
    newStudent->grades[0] = grade1;
    newStudent->grades[1] = grade2;
    newStudent->grades[2] = grade3;
    newStudent->grades[3] = grade4;
    newStudent->prev = nullptr;
    newStudent->next = nullptr;
    return newStudent;
}


void new_stud(Student *&head, const char *surname, int grade1, int grade2, int grade3, int grade4) {
    Student *newStudent = createStudent(surname, grade1, grade2, grade3, grade4);
    if (head == nullptr) {
        head = newStudent;
    } else {
        Student *current = head;
        while (current->next != nullptr) {
            current = current->next;
        }
        current->next = newStudent;
        newStudent->prev = current;
    }
}


void delete_st(Student *&head, Student *studentToDelete) {
    if (studentToDelete == nullptr) {
        return;
    }
    if (studentToDelete == head) {
        head = head->next;
    }
    if (studentToDelete->prev != nullptr) {
        studentToDelete->prev->next = studentToDelete->next;
    }
    if (studentToDelete->next != nullptr) {
        studentToDelete->next->prev = studentToDelete->prev;
    }
    delete studentToDelete;
}

// Функция для проверки оценок студента
bool hasFailingGrade(Student *student) {
    for (int i = 0; i < 4; ++i) {
        if (student->grades[i] < 3) {
            return true;
        }
    }
    return false; // Все оценки удовлетворительные
}


void print_st(Student *head) {
    Student *current = head;
    while (current != nullptr) {
        cout << current->surname << " ";
        for (int i = 0; i < 4; ++i) {
            cout << current->grades[i] << " ";
        }
        cout << endl;
        current = current->next;
    }
}

// Функция для удаления студентов с неудовлетворительными оценками
void del_st(Student *&head) {
    Student *current = head;
    while (current != nullptr) {
        if (hasFailingGrade(current)) {
            Student *studentToDelete = current;
            current = current->next;
            delete_st(head, studentToDelete);
        } else {
            current = current->next;
        }
    }
}


int main() {
    Student *studentsList = nullptr;

    new_stud(studentsList, "Иванов", 5, 4, 3, 5);
    new_stud(studentsList, "Петров", 4, 5, 3, 4);
    new_stud(studentsList, "Сидоров", 3, 2, 1, 3);
    new_stud(studentsList, "Смирнов", 2, 5, 4, 3);
    new_stud(studentsList, "Козлов", 5, 3, 4, 5);

    cout << "Список студентов до удаления:" << endl;
    print_st(studentsList);

    del_st(studentsList);

    cout << endl << "Список студентов после удаления:" << endl;
    print_st(studentsList);

    return 0;
}








№3
#include <iostream>
#include <cstring>
using namespace std;

struct Student {
    char *surname;
    int grades[4];
    Student *left;
    Student *right;
};

// Функция для создания новой структуры Student
Student *createStudent(const char *surname, int grade1, int grade2, int grade3, int grade4) {
    Student *newStudent = new Student;
    newStudent->surname = strdup(surname);
    newStudent->grades[0] = grade1;
    newStudent->grades[1] = grade2;
    newStudent->grades[2] = grade3;
    newStudent->grades[3] = grade4;
    newStudent->left = nullptr;
    newStudent->right = nullptr;
    return newStudent;
}

// добавление нового студента
void addStudent(Student *&root, const char *surname, int grade1, int grade2, int grade3, int grade4) {
    if (root == nullptr) {
        root = createStudent(surname, grade1, grade2, grade3, grade4);
    } else {
        if (strcmp(surname, root->surname) < 0) {
            addStudent(root->left, surname, grade1, grade2, grade3, grade4);
        } else {
            addStudent(root->right, surname, grade1, grade2, grade3, grade4);
        }
    }
}

// Вывод фамилий по возрастанию
void printInOrder(Student *root) {
    if (root != nullptr) {
        printInOrder(root->left);
        cout << root->surname << endl;
        printInOrder(root->right);
    }
}

// Вывод фамилий по убыванию
void printReverseOrder(Student *root) {
    if (root != nullptr) {
        printReverseOrder(root->right);
        cout << root->surname << endl;
        printReverseOrder(root->left);
    }
}

// Поиск студента
Student *findStudent(Student *root, const char *surname) {
    while (root != nullptr) {
        if (strcmp(surname, root->surname) == 0) {
            return root;
        } else if (strcmp(surname, root->surname) < 0) {
            root = root->left;
        } else {
            root = root->right;
        }
    }
    return nullptr; // Студент не найден
}


int main() {
    Student *root = nullptr;

    // Добавляем студентов в дерево
    addStudent(root, "Иванов", 5, 4, 3, 5);
    addStudent(root, "Петров", 4, 5, 4, 4);
    addStudent(root, "Сидоров", 3, 2, 2, 5);
    addStudent(root, "Смирнов", 2, 4, 2, 3);
    addStudent(root, "Козлов", 5, 4, 5, 4);

    cout << "Фамилии студентов по возрастанию:" << endl;
    printInOrder(root);

    cout << endl << "Фамилии студентов по убыванию:" << endl;
    printReverseOrder(root);

    // Поиск студента по фамилии
    cout << endl << "Введите фамилию студента для поиска: ";
    char searchSurname[50];
    cin.getline(searchSurname, 50);

    Student *foundStudent = findStudent(root, searchSurname);
    if (foundStudent != nullptr) {
        cout << "Студент с фамилией " << searchSurname << " найден." << endl;
        cout << "Оценки студента " << searchSurname << ": ";
        for (int i = 0; i < 4; ++i) {
            cout << foundStudent->grades[i] << " ";
        }
        cout << endl;
    } else {
        cout << "Студент с фамилией " << searchSurname << " не найден." << endl;
    }

    return 0;
}

